<?php   if ( ! defined('BASEPATH')) exit('No direct script access allowed');  
    
function day($tgl)
  {  
     $tanggal = substr($tgl,8,2);   
     return $tanggal;         
  }
  
  function num($tgl)
  {  
     $tanggal = substr($tgl,9,1);   
     return $tanggal;         
  }
  
  
  function month($tgl)
  {  
     $tanggal = substr($tgl,8,2);  
     $bulan = substr($tgl,5,2);    
     return $bulan;         
  }
  
  function year($tgl)
  {    
     $tahun = substr($tgl,0,4);  
     return $tahun;         
  }
      
 function indo_tgl($tgl,$format='')
  {  
     $tanggal = substr($tgl,8,2);  
     $bulan = substr($tgl,5,2);	 
     $tahun = substr($tgl,0,4);
	 if($format){
		$data	= $tanggal.$format.$bulan.$format.$tahun;  
	 } else {
		$data	= $tanggal.'-'.$bulan.'-'.$tahun;  
	 }
     return	$data;        
  }
  
  function mysql_date($date,$format='')
  {  // 31/11/2011
     $day = substr($date,0,2);  
     $month = substr($date,3,2);	 
     $year = substr($date,6,4);
	 if($format){
		$data	= $year.$format.$month.$format.$day;  
	 } else {
		$data	= $year.'-'.$month.'-'.$day;  
	 }
     return	$data;        
  }     
  
  function indo_tgl_time($tgl)
    {  
      $tanggal = substr($tgl,8,2);  
      $bulan = getBulan(substr($tgl,5,2));  
      $tahun = substr($tgl,0,4);  
      $jam = substr($tgl,11,2);  
      $menit = substr($tgl,14,2);  
      return $tanggal.' '.$bulan.' '.$tahun.' '.$jam.':'.$menit.' WIB' ;        
        
    }  
        
  function getBulan($bln)
  {  
                   switch ($bln){  
                   case 1:   
                   return "Januari";  
                          break;  
                   case 2:  
                   return "Februari";  
                          break;  
                       case 3:  
                           return "Maret";  
                           break;  
                       case 4:  
                           return "April";  
                           break;  
                      case 5:  
                           return "Mei";  
                          break;  
                      case 6:  
                           return "Juni";  
                          break;  
                      case 7:  
                          return "Juli";  
                          break;  
                      case 8:  
                          return "Agustus";  
                          break;  
                      case 9:  
                          return "September";  
                          break;  
                      case 10:  
                          return "Oktober";  
                          break;  
                      case 11:  
                          return "November";  
                           break;  
                       case 12:  
                           return "Desember";  
                          break;  
                   }  
  }
  
  function daydata($day,$mn)
  {
       $sql="SELECT DAY(date_h) as day FROM josh_holiday WHERE DAY(date_h)='$day' AND MONTH(date_h)='$mn' AND YEAR(date_h)='2010'"; 
       $exe=mysql_query($sql);
       $rec2=mysql_fetch_array($exe);
       echo $rec2['day'];
  } 
  
 
function datediff($d1, $d2)
{  
	$d1 = (is_string($d1) ? strtotime($d1) : $d1);  
	$d2 = (is_string($d2) ? strtotime($d2) : $d2);  
	$diff_secs = abs($d1 - $d2);  
	$base_year = min(date("Y", $d1), date("Y", $d2));  
	$diff = mktime(0, 0, $diff_secs, 1, 1, $base_year);  
	return array( "years" => date("Y", $diff) - $base_year,  "months_total" => (date("Y", $diff) - $base_year) * 12 + date("n", $diff) - 1,  "months" => date("n", $diff) - 1,  "days_total" => floor($diff_secs / (3600 * 24)),  "days" => date("j", $diff) - 1,  "hours_total" => floor($diff_secs / 3600),  "hours" => date("G", $diff),  "minutes_total" => floor($diff_secs / 60),  "minutes" => (int) date("i", $diff),  "seconds_total" => $diff_secs,  "seconds" => (int) date("s", $diff)  );  
 }  